﻿using MediatR;
using MeetingRoomBooking.Application.Common.Models;
using MeetingRoomBooking.Application.Rooms.Commands;
using MeetingRoomBooking.Application.Rooms.Queries;
using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;

namespace WebAPI.Controllers;

[Route("api/[controller]")]
[ApiController]
[Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)]
public class RoomController : ControllerBase
{
    private readonly IMediator _mediator;

    public RoomController(IMediator mediator)
    {
        _mediator = mediator;
    }

    [HttpPost]
    [Route("create")]
    public async Task<int> CreateRoom([FromBody]CreateRoomCommand command)
    {
       return await _mediator.Send(command);
    }

    [HttpPut]
    [Route("update")]
    public async Task UpdateRoom([FromBody] UpdateRoomCommand command)
    {
        await _mediator.Send(command);
    }

    
    [HttpDelete]
    [Route("rooms/{id}")]
    public async Task DeleteRoom(int id)
    {
        var command= new DeleteRoomCommand { Id = id };
        await _mediator.Send(command);
    }

    [HttpGet]
    [Route("rooms/{pageNumber}/{pageSize}")]
    public async Task<PaginatedList<RoomViewModal>> GetRoomsWithPaginated(int pageNumber, int pageSize)
    {
        var queryParam=new GetRoomsWithPaginationQuery() { PageNumber = pageNumber,PageSize = pageSize};
        var rooms = await _mediator.Send(queryParam);

        return rooms;
    }
}
